import apiMod from '@/apiMod/index'
import { getStore } from '@/utils/store'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '唯一标识',
			prop: 'uniqueKey',
			type: 'input',
			rules: [{ required: true, message: '请输入唯一标识：如 table_name_key' }],
			span: 24,
		},
		{
			label: '表名称',
			prop: 'templateName',
			type: 'input',
			rules: [{ required: true, message: '请输入表名称' }],
			span: 24,
		},
		{
			label: '介 绍',
			prop: 'info',
			type: 'textarea',
			span: 24,
		},
	],
}

export const tempTableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '表格编号', prop: 'templateNo' },
		{ label: '唯一标识', prop: 'uniqueKey' },
		{ label: '表名称', prop: 'templateName' },
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '90px',
	column: [
		{
			label: '唯一标识',
			prop: 'result',
			type: 'text',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '模板名称', prop: 'fieldName', width: 200 },
		{ label: '唯一标识', prop: 'result', width: 160 },
		{ label: '数据', prop: 'itemData' },
		{
			label: '操作',
			prop: 'menu',
			width: 230,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_tableItem_page',
	add: 'view_tableItem_add',
	edit: 'view_tableItem_edit',
	delete: 'view_tableItem_del',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '模板数据',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '创建',
	tipLabel: 'indexKey',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuAction: [
		{
			label: '模板管理',
			type: 'primary',
			icon: 'edit',
			operate: 'template',
			auth: 'view_tableTemplate_page',
			show: true,
		},
	],
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	operateFormate: async (row, type) => {
		return new Promise((resolve, reject) => {
			resolve(row)
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			resolve(query)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item, index) => {
					if (item.itemData) {
						item.itemData = JSON.parse(item.itemData)
					}
					item.indexKey = index + 1
					return item
				})
			)
		})
	},
	dialogConfig: {
		width: '65%',
	},
	searchConfig,
	tableConfig,
}
